package com.mahjong.server.component.logic.handler;

import org.apache.log4j.Logger;
import org.apache.mina.core.session.IoSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.mahjong.server.common.Common;
import com.mahjong.server.component.logic.main.KHMahjongAction;
import com.mahjong.server.mina.protocol.AbsMessageProtocol;
import com.mahjong.server.mina.protocol.DataBuf;
import com.mahjong.server.mina.protocol.MessageProtocol;

/**
 * 摸牌
 * @author yougang
 * @date 2013-3-5 上午10:59:26
 * @Description 麻将请求
 */
@Component
@Scope("prototype")
public class MoPaiReq extends MessageProtocol {

	private static final byte TAG = Common.Req;

	private static final short PROTOCOL_NUM = 0x0107;

	private Logger log = Logger.getLogger(this.getClass());

	KHMahjongAction action = new KHMahjongAction();
	
	private int roomId;

	@Override
	public short getProtocolNum() {
		return PROTOCOL_NUM;
	}

	@Override
	public byte getTag() {
		return TAG;
	}

	@Override
	public AbsMessageProtocol execute(IoSession session, AbsMessageProtocol req) {
		log.debug(this.getClass().getSimpleName() + " execute");
		if (roomId>0) {
			return new MoPaiResp(action.buHua(roomId));
		} else {
			return new MoPaiResp(null);
		}
	}

	@Override
	public void reqDecode(DataBuf buf) {
		log.debug(this.getClass().getSimpleName() + " decode");
		roomId = buf.getInt();
	}
}
